package com.fengye.algorithms.leecode;

import com.fengye.algorithms.leecode.common.TreeNode;

/**
 * @Author fengye
 * @Date 2023/4/18 7:43
 **/
public class PathSum112 {
    public static void main(String[] args) {
        TreeNode root1 = new TreeNode(1);
        TreeNode root2 = new TreeNode(1, new TreeNode(2), null);
    }
    public boolean hasPathSum(TreeNode root, int targetSum) {
        if(root == null && targetSum != 0) {
            return false;
        }

        if(root.left == null && root.right == null) {
            return root.val == targetSum;
        }

        return hasPathSum(root.left, targetSum - root.val)
                || hasPathSum(root.right, targetSum - root.val);
    }

    public int dps(TreeNode node) {
        if(node == null) {
            return 0;
        }

        int count = node.val;
        int left = 0;
        int right = 0;
        if(node.left != null) {
            left = dps(node.left);
        }

        if(node.right != null) {
            right = dps(node.right);
        }

        return count + Math.max(left,right);
    }
}
